Skip to content

Delete src/lib (ITensorsExtensions + BaseExtensions submodules) - #364

Merged
mtfishman merged 5 commits into
mainfrom
mf/itensorsextensions-cleanup
May 12, 2026
Merged

mtfishman merged 5 commits into
mainfrom
mf/itensorsextensions-cleanup

Conversation

@mtfishman

@mtfishman mtfishman commented May 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Cleanup pass over src/lib/ and related dead code. Every helper that survived an audit now lives in the single src/ or test/ file that uses it; everything else was dead, test-only, or architecturally misplaced.

  • src/lib/ITensorsExtensions/ and src/lib/BaseExtensions/ — both submodules deleted. Live helpers moved to their consumers: eigendecomp / map_eigvals → src/apply.jl, tensor_sum / maybe_real → src/opsum.jl, the indtype(link_space, site_space) chain → src/indsnetwork.jl, to_tuple → test/utils.jl. Test-only helpers (replace_vertices, group_terms) moved to test/utils.jl. Dead code removed: the *_diag wrappers, diagblocks, LinearAlgebra.isdiag(::ITensor), is_delta, the _contract(::Key) and replaceinds(::Dict) patches, and the entire promote_indtypeof / trivial_space / promote_indtype chain whose only callers were test-internal.
  • map_eigvals fermion branch — make_bosonic and the using_auto_fermion() wrapper are gone. Corresponding "Fermionic map eigvals tests" testset dropped along with the capability.
  • apply(::Op|::Prod|::Scaled, ::AbstractITensorNetwork) — three dead methods in src/apply.jl. TEBD calls apply(::Vector{ITensor}, ψ) after materializing the operator tree via Vector{ITensor}(::Prod, ::IndsNetwork).
  • apply NamedEdge arm — apply(::Union{NamedEdge, ITensor}, ::TN), apply(::Union{Vector{NamedEdge}, Vector{ITensor}}, ::TN), and simple_update_bp(::Union{NamedEdge, ITensor}, ...) narrowed to just ::ITensor / ::Vector{ITensor}. No callers exercised the NamedEdge arm.
  • src/partitioneditensornetwork.jl — deleted. Sole content was a linkinds(::PartitionedGraph, ::QuotientEdge) wrapper used only by the BPC linkinds method; inlined into src/caches/abstractbeliefpropagationcache.jl.
  • Project.toml — 8 unused dependencies removed (AbstractTrees, Combinatorics, Compat, ConstructionBase, IterTools, SerializedElementArrays, Suppressor, TimerOutputs). Tests aren't using them either.
  • Test rename — test/test_itensorsextensions.jl → test/test_map_eigvals.jl.
  • Docs — pruned stale entries in docs/src/experimental_methods.md, docs/src/interface_methods.md, docs/src/deprecated_methods.md.

Targeting the 0.22.0-DEV accumulator.

🤖 Generated with Claude Code

Cross-codebase usage audit found ~110 of the submodule's 258 lines
uncalled. Three groupings of changes:

**Dead-code deletions:**

- `sqrt_diag` / `inv_diag` / `invsqrt_diag` / `pinv_diag` / `pinvsqrt_diag`
  (five convenience wrappers around `map_diag`, zero callers).
- `diagblocks` (both `Tensor` and `ITensor` methods, zero callers) along
  with its supporting `DenseTensor` overloads of `NDTensors.blockoffsets`
  / `nzblocks` / `blockdim` (only consumer was the now-dead `diagblocks`).
- `LinearAlgebra.isdiag(::ITensor)` (zero callers; `apply.jl` and the
  internal `map_eigvals` reference resolve to `ITensors.isdiag`).
- `is_delta` (three methods, zero callers).
- `ITensors._contract(::Key)` dispatch patch (bypassed because
  `contract.jl:18` unwraps `Key`-wrapped sequences via `deepmap` before
  reaching `_contract`).
- `ITensors.replaceinds(::ITensor, ::Dict{<:Index, <:Index})` performance
  patch (zero callers in src/, test/, or ext/).

**Type-system block transitively dead — entry chain `trivial_space(x)`
→ `promote_indtypeof(x)` had only test callers:**

- `make_bosonic` and the `using_auto_fermion` / `has_fermionic_subspaces`
  fermion branch in `map_eigvals`. The corresponding "Fermionic map
  eigvals tests" testset in `test_itensorsextensions.jl` is dropped.
  The fermion-agnostic "Fermionic eigendecomp" testset (which tests
  `eigendecomp` directly) stays.
- `promote_indtypeof(::AbstractITensorNetwork)`, `promote_indtypeof
  (::AbstractIndsNetwork)`, and the `function promote_indtypeof end`
  declaration.
- `indtype(::ITensor)`, `indtype(::IndsNetwork)`, and `indtype(::Type{
  <:IndsNetwork{V, I}})`. The user-facing `indtype(link_space,
  site_space)` 4-form (used by the `IndsNetwork{V,I}` constructor to
  infer `I`) stays.
- `promote_indtype(::Vararg{Type{<:Index}})`, `promote_indtype_rule`,
  `promote_spacetype_rule` (four methods), `spacetype` — all only
  reached through the deleted `promote_indtypeof` chain.
- `trivial_space` (all four methods) — replaced at its single test
  callsite by an inline `hasqns`-conditional helper in `test/utils.jl`.

**Test-only relocations:**

- `replace_vertices` and its internal `set_sites` helper, used only by
  `test/test_opsum_to_ttn_mpo_cross_check.jl`, move to `test/utils.jl`.
- `group_terms`, used only by `test/test_tebd.jl`, moves to
  `test/utils.jl`.
- `src/lib/ITensorsExtensions/src/opsum.jl` is deleted outright.

**Doc cleanup:**

- Drop the `promote_indtypeof(is::AbstractIndsNetwork)` and `indtype
  (inds_network::IndsNetwork)` entries in `docs/src/experimental_methods
  .md`.

Final state: the submodule keeps `tensor_sum`, `eigendecomp` +
`map_eigvals` (now fermion-free), and the focused type-system chain
supporting the `IndsNetwork{V,I}` constructor — `IsIndexSpace`,
`indtype(link_space, site_space)` family, `indtype(space)`, `_indtype`.
About 60 LOC instead of 258.
@codecov

codecov Bot commented May 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.08%. Comparing base (10d62dc) to head (22fddab).

Files with missing lines Patch % Lines
src/indsnetwork.jl 90.00% 1 Missing ⚠️
src/opsum.jl 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #364      +/-   ##
==========================================
+ Coverage   74.96%   76.08%   +1.12%     
==========================================
  Files          63       57       -6     
  Lines        2820     2710     -110     
==========================================
- Hits         2114     2062      -52     
+ Misses        706      648      -58     
Flag Coverage Δ
docs 52.13% <2.94%> (+2.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

After this collapse, src/lib/ goes away entirely. Each helper now lives
in the single src/ or test/ file that uses it:

- `eigendecomp` and `map_eigvals` move from `lib/ITensorsExtensions/`
  into `src/apply.jl` (only consumer in `src/` was `simple_update_bp`).
  Both are now module-level `ITensorNetworks` functions; `src/apply.jl`
  drops the `ITensorsExtensions.` qualifier on its four call sites.

- `tensor_sum` moves from `lib/ITensorsExtensions/` into `src/opsum.jl`
  (only consumer was `ITensors.ITensor(::Sum, ::IndsNetwork)` in the
  same file).

- The `indtype(link_space, site_space)` 4-form, `indtype(space)`,
  `_indtype` family, and `IsIndexSpace` move from
  `lib/ITensorsExtensions/` into `src/indsnetwork.jl` (only consumer
  was the `IndsNetwork{V, I}(g, link_space, site_space)` constructor).

- `maybe_real` moves from `lib/BaseExtensions/` into `src/opsum.jl`
  (consumers were `src/opsum.jl` and `src/apply.jl`; both files reach
  it as a top-level `ITensorNetworks` function now). `to_tuple` was
  only used in `test/utils.jl::group_terms` and moves there directly.

- `test/test_itensorsextensions.jl` renamed to `test/test_map_eigvals.jl`,
  imports updated from `ITensorNetworks.ITensorsExtensions: ...` to
  `ITensorNetworks: ...`. The testset name changes from
  `"ITensorsExtensions"` to `"map_eigvals"`.

- `include("lib/BaseExtensions/...")` removed from
  `src/ITensorNetworks.jl`; `src/lib/` directory deleted outright.

Net effect: drops two submodules' worth of indirection without losing
any in-tree behavior. All tests pass.
@mtfishman mtfishman changed the title Trim the ITensorsExtensions submodule Delete src/lib (ITensorsExtensions + BaseExtensions submodules) May 11, 2026
mtfishman added 3 commits May 11, 2026 19:49
These three methods in `src/apply.jl` had no callers anywhere — TEBD
calls `apply(::Vector{ITensor}, ψ)` after materializing the Trotter
product into ITensors via `Vector{ITensor}(::Prod, ::IndsNetwork)`,
not `apply(::Op|::Prod|::Scaled, ψ)`. The rest of the OpSum→ITensor
chain in `src/opsum.jl` (including `tensor_sum` and `maybe_real`) is
still alive through that materialization step and stays.
Three follow-up cleanups beyond the `src/lib/` collapse:

- Remove 8 `Project.toml` deps that have zero references anywhere in
  `src/`, `ext/`, or `docs/`: `AbstractTrees`, `Combinatorics`, `Compat`,
  `ConstructionBase`, `IterTools`, `SerializedElementArrays`,
  `Suppressor`, `TimerOutputs`. Tests aren't using them either —
  `Compat`'s test usage stays in `test/Project.toml`.
- Delete `src/partitioneditensornetwork.jl` (10-line file whose sole
  contents were a `linkinds(::PartitionedGraph, ::QuotientEdge)` wrapper
  used only by `linkinds(::AbstractBeliefPropagationCache,
  ::QuotientEdge)`). Inline the 3-line body into the BPC method.
- Narrow `apply(::Union{NamedEdge, ITensor}, ::AbstractITensorNetwork)`,
  `apply(::Union{Vector{NamedEdge}, Vector{ITensor}}, ::TN)`, and the
  internal `simple_update_bp(::Union{NamedEdge, ITensor}, ...)` to just
  `::ITensor` / `::Vector{ITensor}`. No callers anywhere exercised the
  `NamedEdge` arm.

Doc updates:
- Drop the `partitioneditensornetwork.jl` entry from
  `docs/src/deprecated_methods.md`.
- Narrow the `apply` signature listing in `docs/src/interface_methods.md`
  to match.
Zero references in test/*.jl; was carried over alongside the same dep
in the main Project.toml.
@mtfishman
mtfishman enabled auto-merge (squash) May 12, 2026 00:14
@mtfishman
mtfishman merged commit 43bf3fd into main May 12, 2026
18 checks passed
@mtfishman
mtfishman deleted the mf/itensorsextensions-cleanup branch May 12, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant